<template>
  <div class="xtx-number">
    <div class="label">{{ label }}</div>
    <div class="numbox">
      <a
        href="javascript:;"
        @click="changeNum(-1)"
        :class="{ disabled: modelValue === 1 }"
        >-</a
      >
      <input type="text" :value="modelValue" readonly />
      <a
        href="javascript:;"
        @click="changeNum(1)"
        :class="{ disabled: modelValue === max }"
        >+</a
      >
    </div>
  </div>
</template>

<script>
import {} from 'vue'
export default {
  name: 'XtxNumber',
  props: {
    label: {
      type: String
    },
    modelValue: {
      type: Number,
      default: 1
    },
    min: {
      type: Number,
      default: 1
    },
    max: {
      type: Number,
      default: 100
    }
  },
  setup(props, { emit }) {
    const changeNum = (value) => {
      const temp = props.modelValue + value
      if (temp < props.min || temp > props.max) return
      emit('update:modelValue', temp)
      emit('change', temp)
    }
    return { changeNum }
  }
}
</script>
<style scoped lang="less">
.xtx-number {
  display: flex;
  align-items: center;
  margin-top: 10px;
  .label {
    width: 60px;
    color: #999;
    padding-left: 10px;
  }
  .numbox {
    width: 120px;
    height: 30px;
    border: 1px solid #e4e4e4;
    display: flex;
    > a {
      width: 29px;
      line-height: 28px;
      text-align: center;
      background-color: #f8f8f8;
      font-size: 16px;
      color: #666;
      &.disabled {
        cursor: not-allowed;
      }
      &:first-of-type {
        border-right: 1px solid #e4e4e4;
      }
      &:last-of-type {
        border-left: 1px solid #e4e4e4;
      }
    }
    > input {
      width: 60px;
      padding: 0 5px;
      text-align: center;
      color: #666;
    }
  }
}
</style>
